<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
		<meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache,no-store,must-revalidate">
    <meta http-equiv="Cache" content="no-cache">
    <title>用户管理</title>
    <link rel="stylesheet" href="../../component/pear/css/pear.css" />
    <link rel="stylesheet" href="../../admin/css/other/department.css" />
    <style>
     .auto-report-input-clz{
        width: 350px!important;
      }
    </style>
  </head>
  <body class="pear-container">

    <div class="layui-row layui-col-space10">
      <div class="layui-col-md10 layui-col-md-offset1">
        <div class="layui-card">
          <div class="layui-card-body">
            <div class="layui-form" lay-filter="form1">
              <div class="layui-form-item">
                <div class="layui-inline">
                  <label class="layui-form-label">日报地址</label>
                  <div class="layui-input-inline layui-input-wrap auto-report-input-clz">
                    <input type="tel" name="auto-report-input" autocomplete="off" class="layui-input auto-report-input'">
                  </div>
                  <div class="layui-form-mid" style="padding: 0!important;"> 
                    <button type="button" class="layui-btn layui-btn-primary layui-bg-red" lay-on="auto-report-submit-btn">确定设置</button>
                  </div>
                </div>
              </div>

            </div>
          </div>
        </div>
      </div>
    </div>


    <script src="../../component/layui/layui.js"></script>
    <script src="../../component/pear/pear.js"></script>

    <script type="text/javascript">
      // 加载自定义模块,检查浏览器和token
      layui.extend({
        myheader: "{/}/lay-ext/myheader",
      });
      layui.use(
        ["table", "form", "jquery", "myheader", "popup", "layer", "util"],
        function () {
          let table = layui.table;
          let form = layui.form;
          let $ = layui.jquery;
          let myheader = layui.myheader;
          let popup = layui.popup;
          let layer = layui.layer;
          let util = layui.util;
          
          // 定义全局 ajax的请求头
          myheader.ajaxGlobal(myheader.checkToken().tokenValue);
          // layer.msg('第一个回调', {icon: 1})
          // 定义常量
          const baseUrl = myheader.baseUrl();
          const MODULE_PATH = "operate/";
          const mypage = {};
          // 获取初始化值
          $.ajax(baseUrl+"/systemSetting/getDailyReportAddress",{
            beforeSend:function(){
              layer.load(2, { shade: 0.3 })
            },
            success:function(res){
              // $('.auto-report-input').val(res.data.value)
              form.val('form1',{
                'auto-report-input':res.data.value
              })
            },
            complete:function(){
              layer.closeAll('loading');
            }
          })
          //给 auto-report-submit-btn 绑定事件
          util.on('lay-on',{
            'auto-report-submit-btn':function(){
              // 检查form.val('form1')['auto-report-input'] 最后一个字符是否是\或者/
              if(!(form.val('form1')['auto-report-input'].substr(-1)=='\\' || form.val('form1')['auto-report-input'].substr(-1)=='/' )){
                layer.msg('地址必须以\\或者/结尾', {icon: 2})
                return
              }
              $.ajax(baseUrl+"/systemSetting/setDailyReportAddress",{
                type:'POST',
                contentType:'application/json',
                data:JSON.stringify({
                  value:form.val('form1')['auto-report-input']
                }),
                beforeSend:function(){
                  layer.load(2, { shade: 0.3 })
                },
                success:function(res){
                  if(res.code==200){
                    layer.msg('设置成功', {icon: 1})
                  }else {
                    layer.msg('设置失败', {icon: 2})
                  }
                },
                complete:function(){
                  layer.closeAll('loading');
                }
              })
            }
          })
        }
      );
    </script>

  </body>
</html>
